package com.dt76.smallloanbackendservice.service.lhuaw.impl;

import com.dt76.smallloanbackendservice.mapper.lhuaw.SystemMessageMapper;
import com.dt76.smallloanbackendservice.pojo.lhuaw.SystemMessage;
import com.dt76.smallloanbackendservice.service.lhuaw.SystemMessageService;
import com.dt76.smallloanbackendservice.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemMessageServiceImpl implements SystemMessageService {

    @Autowired
    private SystemMessageMapper systemMessageMapper;

    @Override
    public List<SystemMessage> getAll() {
        return systemMessageMapper.getAll();
    }

    @Override
    public Page getAllSystemMessage(int pageIndex, String messageTitle, String publisher) {
        Page page = new Page();
        page.setPageIndex(pageIndex);
        page.setTotalCount(systemMessageMapper.qryConditionCount(messageTitle, publisher));
        List<SystemMessage> systemMessageList = systemMessageMapper.qryConditionPageAll((page.getPageIndex() - 1) * page.getPageSize(),
                page.getPageSize(), messageTitle, publisher);
        System.out.println(systemMessageList);
        page.setRows(systemMessageList);
        return page;
    }

    @Override
    public void deleteSystem(int sId) {
        systemMessageMapper.deleteSystem(sId);
    }

    @Override
    public void addSystem(SystemMessage systemMessage) {
        systemMessageMapper.saveSystem(systemMessage);
    }

    @Override
    public SystemMessage seeSystem(int sId) {
        return systemMessageMapper.seeSystem(sId);
    }

}
